/*绑定回车到查询按钮*/
$(function(){
	$(document).keydown(function(){ 
		if(event.keyCode==13){ 
		$(".obtn1").trigger('click'); 
		}
	});
});
$(function(){
	$('.dropdown-menu li').click(function(){
		var bText = $(this).text();
        var bValue = $(this).val();
        $(this).parent().siblings(".dropdown-toggle").html(bText+'<b></b>');
        $(this).parent().siblings("#kcyj-leixing").val(bValue);
        $(this).parent().css("display","none");
        leixing=bValue;
        dwpanduan=false;
  		getYuJlb();
	});
});
var kucunyjid = null;
function hulue(id,prehanghao,mingcheng) {
	kucunyjid = id;
	mingcheng=mingcheng.substring(0,15);
	$('#tbkucunyj').find('tr[id="yjhang'+prehanghao+'"]').siblings('tr').removeClass('list-tr');
	$('#tanceng-nr').text('是否忽略'+mingcheng+'的库存预警');
	$('#tanceng').modal();
	
}
$(document).on('click','.queding',function(){
	$.ajax({
		type:"POST",
        //获取json文件路径
        url:path+"/kucunyj/huluekcyj",
        //传送数据
        data:{id:kucunyjid},
        //请求成功完成后要执行的方法
        success: function(data){
        	$("#tanceng").modal('hide');
        	getYuJlb();
        	notifySuccess('忽略成功');
        }
	});
});

var dingwei='';
var dwpanduan=true;
var dwleixing='';
var dwflag='';
var kucunpcqx;
var pageNumber;
function getCanshu(predwpageNo,predwleixing,predwid,predwflag,isKucunpc){
	dwid = predwid;
	dwleixing = predwleixing;
	dwflag = predwflag;
	kucunpcqx = isKucunpc;
	if(dwid!='null'){
		leixing=dwleixing;
		pageNumber=predwpageNo;
		$('#kcyj-leixing').val(dwleixing);
		if(dwleixing==1) {
			$("#kcyj-leixingdiv").text("药品");
		}else if(dwleixing==2) {
			$("#kcyj-leixingdiv").text("耗材");
		}
	}
	if(predwpageNo!='null'){
		pageNumber=predwpageNo;
	}
	getYuJlb();
}
//查询点击
var leixing="";
$(document).on('click','.crumbs-button ul li.obtn1',function(){
	leixing=$("#kcyj-leixing").val();
	dwpanduan=false;
	pageNumber = 1;
	getYuJlb();
});
//清除条件
$(".crumbs-button ul li.obtn2").click(function(){
    $("#kcyj-leixing").val(0);
    $("#kcyj-leixingdiv").html('全部'+'<b></b>');
    leixing='';
    dwpanduan=false;
    pageNumber = 1;
    getYuJlb();
   
});
//处理按钮
function chuli(zhensuoypid,zhensuohcid,leixing,pageNo){
	var dwyjleixing=$("#kcyj-leixing").val();//定位预警类型
	//库存批次权限
	if(kucunpcqx == 'false') {
		if(leixing==2){
			$("#cedan").load(path+"/views/kucun/haocai-detail.jsp?FLAG=0&ID="+zhensuohcid+"&dwpageNo="+pageNo+"&dwleixing="+dwyjleixing);
			$(".g-left-nav li span").css("border","none");
	        $(".g-left-nav li span.nav-comsumer-goods").css("border","solid 1px #00b472");
		}else if(leixing==1){
			$("#cedan").load(path+"/views/kucun/yaopin-detail.jsp?FLAG=1&ID="+zhensuoypid+"&dwpageNo="+pageNo+"&dwleixing="+dwyjleixing);
			$(".g-left-nav li span").css("border","none");
	        $(".g-left-nav li span.nav-durg").css("border","solid 1px #00b472");
		}
	} else {
		window.location.href = path+"/views/kucun/rukugl/rukugl-dengji.jsp?zhensuohcid="+zhensuohcid+"&zhensuoypid="+zhensuoypid;
		$(".g-left-nav li span").css("border","none");
        $(".g-left-nav li span.shangpinrk").css("border","solid 1px #00b472");
	}
}

//库存预警页面显示
function getYuJlb(){
	var totalNumber =0;
	var params={
		leixing:leixing,
	};
	$.ajax({
       //请求方式为get
       type:"get",
       //获取json文件路径
       url:"./kucunyj/getCount",
       data:params,
       async:false,
       //请求成功完成后要执行的方法
       success: function(data){
       totalNumber = data;
       if(totalNumber==0){
			$("#a-table-title").css("display","none");
			$("#kcyj-img").html("<img src='"+path+"/image/chaxtj/cxtj-nobody.png'>");
		}else{
			$("#a-table-title").css("display","block");
			$("#kcyj-img").html("");
		}
      }
   });
	
	 function createYujlb(name) {
		$('#tbkucunyj').html('');
			var container = $('#pagination-'+name);
			container.pagination({
			dataSource:'./kucunyj/getByPage?leixing='+leixing,
			locator: '',
			pageSize: 12,
			totalNumber: totalNumber,
			pageNumber:pageNumber,
			showNavigator: true,
	   	    formatNavigator: '共 <%= totalNumber %> 条',
			callback: function(data, pagination){
				if(data!='') {
					var content = '';
					$(data).each(function(index,e){
						var leixing = '';
						if(this.leixing==1) {
							leixing = '药品';
						}else if(this.leixing==2) {
							leixing = '耗材';
						}
						if(this.bieming != null&& this.bieming !=''){
							var mingcheng = this.bieming;
						} else {
							var mingcheng = this.mingcheng;
						}
						var hanghao=(((pagination.pageNumber-1)*pagination.pageSize)+index+1);
						content += '<tr id="yjhang'+hanghao+'">'+
						'<td width="20%">'+hanghao+'</td>'+
		                '<td class="left" width="20%">'+mingcheng+'</td>'+
		                '<td width="20%">'+leixing+'</td>'+
		                '<td width="20%">'+this.kucunsl+this.kucundw+'</td>'+
		                '<td width="20%">'+
	                        '<div class="table-operation">'+
	                            '<span class="obtn4"  onclick="chuli('+this.zhensuoypid+','+this.zhensuohcid+','+this.leixing+','+pagination.pageNumber+')">处理</span>'+
	                            '<span class="obtn5" id="'+this.id+'" onclick="hulue('+this.id+','+hanghao+',\''+this.mingcheng+'\')">忽略</span>'+
	                        '</div>'+
	                     '</td>'+
	                     '</tr>';
						if(dwid==this.zhensuoypid||dwid==this.zhensuohcid&&dwflag==this.leixing){
		        			dingwei=hanghao;
		        		}
					});
					$('#tbkucunyj').html(content);
					if(dingwei!=null&&dingwei!=''){
				  		$('#tbkucunyj').find('tr[id="yjhang'+dingwei+'"]').addClass('list-tr');
			  		}
			  		if(!dwpanduan){
				  		$('#tbkucunyj').find('tr[id="yjhang'+dingwei+'"]').removeClass('list-tr');
			  		}
		    	}
			}
		});
		return container;
	}
	 createYujlb('kucunyj');
	 if(totalNumber <= 12) {
			$('#pagination-kucunyj').css('display','none');
		}else{
			$('#pagination-kucunyj').css('display','block');
		}
}